﻿/*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
 *~*  www.PBDesk.com 2010                                                      
 *~*  
 *~*  Project : PBDesk.Utilities                        Namespace : PBDesk.Utilities
 *~*  File : StringExtensionMethods.cs                  Class : StringExtensionMethods
 *~*  
 *~*  Author : Pinal Bhatt (pinal.bhatt@PBDesk.com)
 *~*  Version History
 *~*            Ver. 1.0     Date 12-Oct-2010       Pinal Bhatt
 *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace PBDesk.Utilities
{
    /// <summary>
    /// Static Class containing Extension Methods for strings.
    /// Extending System.String functionalities
    /// </summary>
    public static class StringExtensions
    {
        /// <summary>
        /// Indicates whether invoking string object is null or not.
        /// </summary>
        /// <param name="inputString"></param>
        /// <returns>True, if string is null else returns false</returns>
        public static bool IsNull(this string inputString)
        {
            return (inputString == null);
        }

        /// <summary>
        /// Indicates whether invoking string object is null or not.
        /// </summary>
        /// <param name="inputString"></param>
        /// <returns>True, if string is not null else returns false</returns>
        public static bool IsNotNull(this string inputString)
        {
            return (inputString != null);
        }

        /// <summary>
        /// Indicates whether invoking string object is null or an empty string.
        /// </summary>
        /// <param name="inputstr"></param>
        /// <returns></returns>
        public static bool IsNullOrEmpty(this string inputstr)
        {
            return string.IsNullOrEmpty(inputstr);
        }

        /// <summary>
        /// Indicates whether invoking string object is not null and not an empty string.
        /// </summary>
        /// <param name="inputString"></param>
        /// <returns></returns>
        public static bool IsNotNullAndNotEmpty(this string inputString)
        {
            return !string.IsNullOrEmpty(inputString);
        }


        /// <summary>
        /// Returns true if invoking string matches with regex pattern
        /// </summary>
        /// <param name="original"></param>
        /// <param name="regex"></param>
        /// <returns></returns>
        public static bool IsRegexMatch(this string original, string regex)
        {
            return Regex.IsMatch(original, regex);
        }

        public static T ToEnum<T>(this string inString, bool ignoreCase = true, bool throwException = true) where T : struct
        {
            return (T)MyUtils.ParseEnum<T>(inString, ignoreCase, throwException);
        }
        public static T ToEnum<T>(this string inString, T defaultValue, bool ignoreCase = true, bool throwException = false) where T : struct
        {
            return (T)MyUtils.ParseEnum<T>(inString, defaultValue, ignoreCase, throwException);
        }
    }
}
